package com.cw.DesignModel23.Structural.ProxyPattern.动态代理;

import com.cw.DesignModel23.Structural.ProxyPattern.静态代理.*;
public class Main {
    public static void main(String[] args) {
        Order order = new Order("书籍订单", 1);

        IOrderDao dao = new OrderDaoImpl();
        IOrderService service = new OrderServiceImpl(dao);

        // 不使用代理的情况
        service.saveOrder(order);

        System.out.println();

        // 使用静态代理的情况
        OrderServiceStaticProxy proxy = new OrderServiceStaticProxy(service);
        proxy.saveOrder(order);

        System.out.println();

        // 使用动态代理的情况
        IOrderService orderServiceDynamicProxy = (IOrderService) new OrderServiceDynamicProxy(service).bind();
        orderServiceDynamicProxy.saveOrder(order);
        //动态代理的核心步骤是 Proxy.newProxyInstance 调用 ;
        //传入3个参数分别是:① 目标对象类加载器 ,② 目标对象实现的接口 ,③ 动态代理类本身(InvocationHandler实现类);

    }
}

